// pages/my/my.js

var WXBizDataCrypt = require('../../utils/cryptojs/RdWXBizDataCrypt.js');
//获取应用实例
var app = getApp();
var util = require('../../utils/util.js')
var key = app.globalData.key;
const resurl = app.globalData.resurl;
Page({
  data: {
    adverShow: true,
    gameShow: false,
    touxiang: '/images/avatar_login.png',
    loginName: '点击登录',
    yuanbao: '',
    myRestMoney: '',
    invite: '19580630',
    isReview: '',
    isReview1: '',

  },
  // 关闭banner广告
  adClose: function () {
    this.setData({
      adverShow: false,
      gameShow: true,
    })
  },
  gameClose: function () {
    this.setData({
      gameShow: false,
    })
  },
  bindcode: function (e) {
    //const index= e.currentTarget.dataset.index;//获取点击event的索引
    //const url= e.currentTarget.dataset.url;//获取点击event的索引
    //console.log(e)
    wx.navigateTo({
      url: '/pages/invite/invite',
    })
  },
  friends: function (e) {
    //const index= e.currentTarget.dataset.index;//获取点击event的索引
    //const url= e.currentTarget.dataset.url;//获取点击event的索引
    //console.log(e)
    wx.navigateTo({
      url: '/pages/share/share',
    })
  },
  connected: function () {
    // wx.navigateTo({
    //   url:'/pages/connecting/connecting',
    // })
  },
  getmoney: function () {
    wx.navigateTo({
      url: '/pages/getMoney/getMoney',
    })
  },
  advice: function () {
    wx.navigateTo({
      url: '/pages/advice/advice'
    })
  },
  aboutUs: function () {
    wx.navigateTo({
      url: '/pages/aboutours/aboutours'
    })
  },
  clockLogin: function () {
  },
  copyText: function (e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.invite,
      success: function () {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 1000
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.getUserInfo();
    var isReview = wx.getStorageSync("isReview");
    var isReview1 = wx.getStorageSync("isReview1");
    that.setData({
      isReview: isReview,
      isReview1: isReview1,
    })
  },
  // 获取用户信息头像Id之类的
  getUserInfo: function () {
    var that = this;
    var userId = wx.getStorageSync("userId");
    var _data = {
      deviceProperties: app.globalData.deviceProperties,
      user: {
        userId: userId,
      }
    }
    _data = JSON.stringify(_data);
    _data = util.base64_encode(_data);
    _data = util.xxtea_encrypt(_data, key);
    //获取用户信息接口
    wx.request({
      url: resurl + '/interface/sdkData?requestId=3&a=1&b=2',
      data: _data,
      header: {
        "content-type": "application/json",
        "dataType": "json",
      },
      method: "post",
      success: function (res) {
        res = util.xxtea_decrypt(res.data, key);
        res = util.base64_decode(res);
        res = JSON.parse(res);
        if (res.resultCode === 0) {
          res = JSON.parse(res.data);
          var loginName = unescape(res.user.realName);
          var myRestMoney = Math.floor(res.user.money / 10000 * 100) / 100;
          that.setData({
            touxiang: res.user.userLogo,
            loginName: loginName,
            myId: res.user.userId,
            yuanbao: res.user.money,
            myRestMoney: myRestMoney,
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})